/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



package sonia.golf;

//~--- non-JDK imports --------------------------------------------------------

import sonia.golf.dao.DAOFactory;

//~--- JDK imports ------------------------------------------------------------

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 * @author Sebastian Sdorra
 */
public class Course
{

  /**
   * Constructs ...
   *
   *
   * @param name
   */
  public Course(String name)
  {
    this.name = name;
    this.creationDate = new Date();
    this.holes = new ArrayList<Hole>();
  }

  /**
   * Constructs ...
   *
   *
   * @param name
   * @param creationDate
   */
  public Course(String name, Date creationDate)
  {
    this.name = name;
    this.creationDate = creationDate;
  }

  /**
   * Constructs ...
   *
   *
   * @param name
   * @param creationDate
   * @param holes
   */
  public Course(String name, Date creationDate, List<Hole> holes)
  {
    this.name = name;
    this.creationDate = creationDate;
    this.holes = holes;
  }

  //~--- methods --------------------------------------------------------------

  /**
   * Method description
   *
   *
   * @param e
   *
   * @return
   */
  public boolean addHole(Hole e)
  {
    loadHoles();

    return holes.add(e);
  }

  /**
   * Method description
   *
   *
   * @param o
   *
   * @return
   */
  public boolean removeHole(Hole o)
  {
    loadHoles();

    return holes.remove(o);
  }

  /**
   * Method description
   *
   *
   * @return
   */
  @Override
  public String toString()
  {
    return name;
  }

  //~--- get methods ----------------------------------------------------------

  /**
   * Method description
   *
   *
   * @return
   */
  public Date getCreationDate()
  {
    return creationDate;
  }

  /**
   * Method description
   *
   *
   * @return
   */
  public int getHoleCount()
  {
    loadHoles();

    return holes.size();
  }

  /**
   * Method description
   *
   *
   * @return
   */
  public List<Hole> getHoles()
  {
    loadHoles();

    return holes;
  }

  /**
   * Method description
   *
   *
   * @return
   */
  public String getName()
  {
    return name;
  }

  //~--- set methods ----------------------------------------------------------

  /**
   * Method description
   *
   *
   * @param holes
   */
  public void setHoles(List<Hole> holes)
  {
    this.holes = holes;
  }

  //~--- methods --------------------------------------------------------------

  /**
   * Method description
   *
   */
  private void loadHoles()
  {
    if (holes == null)
    {
      DAOFactory.getInstance().getCourseDAO().fetchHoles(this);
    }
  }

  //~--- fields ---------------------------------------------------------------

  /** Field description */
  private Date creationDate;

  /** Field description */
  private List<Hole> holes;

  /** Field description */
  private String name;
}
